#
#  dataSource.pm
#  agentes
#
#  Created by Raúl Sánchez Ruiz on 12/12/07.
#  Copyright 2007 __MyCompanyName__. All rights reserved.
#

package dataSource;

use CamelBones qw(:All);

use strict;
use warnings;



class dataSource {
	'super' => 'NSObject'
};

sub init : Selector(init) ReturnType(@) {
	my ($self) = @_;
	#print "entre en init!\n";
	#$self->{datos}=["hola"];
	#print $schema;	
	#$self->{schema} = $basedatos::schema;
	return $self;
}

sub numberOfRowsInTableView :
Selector(numberOfRowsInTableView:)
ArgTypes(@) ReturnType(i)
{
	my ($self) = @_;
	#print "entre en numberOfRowsInTableView!\n";
	#return scalar @{$self->{'InternetServices'}};
	#return 2;
	return scalar list_all_places();
}

sub tableView_objectValueForTableColumn_row :
Selector(tableView:objectValueForTableColumn:row:)
ArgTypes(@@i) ReturnType(@)
{
	my ($self, $tableView, $tableColumn, $row) = @_;
	my @tmp = list_all_places();
	return $tmp[$row]->{_column_data}->{$tableColumn->identifier};
}

sub tableView_setObjectValue_forTableColumn_row :
Selector(tableView:setObjectValue:forTableColumn:row:)
ArgTypes(@@@i) ReturnType(v)
{
	my ($self, $tableView, $newValue, $tableColumn, $row) = @_;
	#my $internetServices = $self->{'InternetServices'};
	#$self->{'InternetServices'}->[$row]->{$tableColumn->identifier} = $newValue;
	#return "hola2";
}

sub list_all_places {
	my $schema = Database::Main->connect('dbi:SQLite:datos.db');
	my @rs = $schema->resultset('Places')->all();
	
	return @rs
}

1;
